﻿using System;
using System.Collections.Generic;

namespace 冒泡排序
{
    internal static class Program
    {
        // ReSharper disable once UnusedParameter.Local
        private static void Main(string[] args)
        {
            int[] arr = new[] {1,5,3,8,9,6,2,4,7};
            Ascending(arr);
            Console.ReadKey();
        }

        private static void Ascending(IList<int> array)
        {
            for (int i = 0; i < array.Count-1; i++)//3个数比2次
            {
                for (int j = 0; j < array.Count-1; j++) //3个数比2次所以Length-1也是防止元素逆出
                {
                    if (array[j] <= array[j + 1]) continue;
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }

            foreach (int v in array)
            {
                Console.WriteLine(v);
            }
            
        }
    }
}
